Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Create a table from frmttable without "\begin{tabular}" and "\end{tabular}"

    I have created a table that fits my exact specifications using frmttable. I'm trying to output this table so that I can import it in LaTeX. I'd like to be able to adjust the column widths, so that I can wrap the first column. This is easy to do within LaTeX if the outputted .tex file doesn't contain the \begin{tabular}{lcc} and \end{tabular} lines. Other stata table commands (e.g. esttab) don't create these lines in latex output. But esttab doesn't have the flexibility of frmttable/outreg. My question is:
    - How can I output a mata structure created with frmttable to a latex file fragment that does not contain the "\begin{tabular}" and "\end{tabular}" code?
    - How can I substitute text with latex code in a table created from a mata structure? [for example, replace "degrees" with "$^{\circ}\$"]

    Here is some basic code that replicates the challenge:
    mat stuff = 3, 5, 8, 2
    frmttable, append(mytable) statmat(stuff) substat(1) sdec(2) nocoltitl rtitles("A long row title describing this confusing variable (degrees celcius)")
    outreg using "MyTable.tex", replay(mytable) ctitles("","Col 1", "Col 2") tex fragment replace


    Here are the contents of the MyTable.tex file:
    \begin{center}
    \begin{tabular}{lcc}
    \hline \noalign{\smallskip} & Col 1 & Col 2\\
    \noalign{\smallskip}\hline \noalign{\smallskip}A long row title describing this variable (degrees celcius) & 3.00 & 8.00\\
    & \begin{footnotesize}(5.00)\end{footnotesize} & \begin{footnotesize}(2.00)\end{footnotesize}\\
    \noalign{\smallskip}\hline\end{tabular}\\
    \end{center}

  • #2
    One way may be to read the file into a strL variable, then search replace, before writing to file:
    Code:
    clear
    set obs 1
    local tex "MyTable.tex"
    local tex2 "MyTable2.tex"
    
    generate strL s = fileread("`tex'") if fileexists("`tex'")
    assert filereaderror(s)==0
    replace s = ustrregexrf(s,"\\begin\{tabular\}\{lcc\}\s*\n{1,2}","")
    replace s = subinstr(s,"\end{tabular}","",1)   
    replace s = subinstr(s,"degrees","$^{\circ}\\$",.)
    gen byte fw = filewrite("`tex2'",s,1)
    Last edited by Bjarte Aagnes; 13 Dec 2017, 15:32.

    Comment


    • #3
      Another option would be to use -filefilter- on the output file to remove those lines.

      Comment

      Working...
      X